package com.runfast.waimai.service.impl;

import com.runfast.common.service.BaseService;
import com.runfast.waimai.dao.model.Notice;
import com.runfast.waimai.dao.model.RunfastDriverApplication;
import com.runfast.waimai.dao.model.RunfastDriverApplicationExample;
import com.runfast.waimai.service.NoticeService;
import com.runfast.waimai.service.RunfastDriverApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RunfastDriverApplicationServiceImpl extends BaseService<RunfastDriverApplication, Integer, RunfastDriverApplicationExample> implements RunfastDriverApplicationService {
    @Autowired
    private NoticeService noticeService;
    public void DriverApplicationToNotice(){
        RunfastDriverApplicationExample example=new RunfastDriverApplicationExample();
        example.createCriteria().andHavereadEqualTo(false);
        List<RunfastDriverApplication> runfastDriverApplicationList=this.mapper.selectByExample(example);
        if(runfastDriverApplicationList.size()>0){
            for(RunfastDriverApplication runfastDriverApplication:runfastDriverApplicationList){
                String gender=null;
                String experienced=null;
                String intention=null;
                if(runfastDriverApplication.getGender()!=null && runfastDriverApplication.getGender()==0){
                    gender="女";
                }else if(runfastDriverApplication.getGender()!=null && runfastDriverApplication.getGender()==1){
                    gender="男";
                }
                if(runfastDriverApplication.getExperienced()!=null && runfastDriverApplication.getExperienced()==1){
                    experienced="是";
                }else{
                    experienced="否";
                }
                if(runfastDriverApplication.getIntention()!=null && runfastDriverApplication.getIntention()==1){
                    intention="兼职";
                }else{intention="全职";}
                Notice notice=new Notice();
                notice.setTitle("骑手招募："+runfastDriverApplication.getName());
                if(runfastDriverApplication.getAgentid()!=null){
                    notice.setAgentid(runfastDriverApplication.getAgentid());
                }else{notice.setOnlyadmin(true);}
                notice.setCreatetime(new Date());
                notice.setHaveread(false);
                notice.setDeleted(false);
                String s="<p class=\"ql-align-justify\"><strong>姓名</strong>："+
                        runfastDriverApplication.getName()+"</p><p class=\"ql-align-justify ql-indent-8\"><br></p><p class=\"ql-align-justify\"><strong>性别</strong>："+gender
                        +"</p><p class=\"ql-align-justify\"><br></p><p class=\"ql-align-justify\"><strong>身份证号</strong>：<span style=\"color: rgb(102, 102, 102);\">"+
                        runfastDriverApplication.getIdnumber()+"</span></p><p class=\"ql-align-justify\"><br></p><p class=\"ql-align-justify\"><strong><u>年龄</u></strong>："+
                        runfastDriverApplication.getAge()+"</p><p class=\"ql-align-justify\"><br></p><p class=\"ql-align-justify\"><strong>手机号</strong>："+runfastDriverApplication.getMobile()
                        +"</p><p class=\"ql-align-justify\"><br></p><p class=\"ql-align-justify\"><strong>期望工作城市</strong>："+runfastDriverApplication.getProvince()+runfastDriverApplication.getCity()
                        +"</p><p class=\"ql-align-justify\"><br></p><p class=\"ql-align-justify\"><strong>是否有物流或者外卖送餐经验：</strong>"+experienced
                        +"</p><p class=\"ql-align-justify\"><br></p><p class=\"ql-align-justify\"><strong>工作意向</strong>："+intention+"</p><p><br></p>";
                notice.setContent(s);
                noticeService.insert(notice);
                runfastDriverApplication.setHaveread(true);
                this.mapper.updateByPrimaryKeySelective(runfastDriverApplication);
            }
        }
    }
}